<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no">
		<title>提现</title>
		<link rel="stylesheet" href="/static/css/style.css" />

	</head>

	<body>
		<div class="container" id="getcash" v-cloak>

			<div class="form form-login form-getcash">
				<div class="unit unit-text">
					慧币余额：<span>${balance}</span>元
				</div>
				<div class="unit unit-money">
					<li @click="tapcash(10)"><span>10</span></li>
					<li @click="tapcash(20)"><span>20</span></li>
					<li @click="tapcash(30)"><span>30</span></li>
					<li @click="tapcash(50)"><span>50</span></li>
					<li @click="tapcash(80)"><span>80</span></li>
					<li @click="tapcash(100)"><span>100</span></li>
					<!--<p>提现费率：{{rate}}%，该笔服务费：{{serviceFee}} 元</p>-->
				</div>
				<div class="unit">
					<i class="icon icon-tixian"></i>
					<input type="text" placeholder="手动输入提现金额" v-model="amount" />
				</div>
				<!--<div class="unit">
					<i class="icon icon-alipay"></i>
					<input type="text" placeholder="输入收款支付宝账号(二选一)" v-model="alipay" />
				</div>-->
				<div class="unit">
					<i class="icon icon-weipay"></i>
					<input type="text" placeholder="输入收款微信号(非昵称)或微信关联手机号" v-model="weixin" />
				</div>

				<div class="unit">
					<a class="btn btn-block btn-round bg-primary" @click="doGetcash">
						确定
					</a>
					<p><i class="icon icon-tishi"></i>每月21号可提现上月结算分红，付款或确认收货后发生退款维权，该比订单分红将失效，提现金额将转入用户的微信账户，我们客服将添加你为好友并转账，请稍后注意通过。</p>

				</div>

			</div>

		</div>

	</body>
	<script src="/static/js/mui.min.js"></script>
	<script src="/static/js/vue.min.js"></script>
	<script src="/static/js/zepto.min.js"></script>
	<script src="/static/js/plugins/popup.js"></script>
	<script src="/static/js/plugins/scroll.js"></script>
	<script src="/static/js/plugins/pullrefresh.js"></script>
	<script type="text/javascript">
		var getcash = new Vue({
			el: '#getcash',
			delimiters: ['${', '}'],
			data: {

				balance: "",
				amount: "",
				rate: 2,
				limit: 10,
				weixin: "",
				alipay: "",
			},
			mounted: function() {
				this.request();

			},

			methods: {
				doBack() {

				},

				request() {
					var self = this;

					$.post('/app/wxmp/user/index', {

					}, function(res) {
						if(res.errno == 0) {
							self.balance = res.data.asset.amount;

						} else {
							popup.prompt(res.errmsg);
						}
					});

				},

				doGetcash() {

					var self = this;

					if(self.balance < self.limit) {
						return popup.toast("满" + self.limit + "元方可提现");
					}

					if(!self.checkAmount(self.amount)) {
						return popup.toast("请输入正确的金额");

					}

					if(self.amount > self.balance) {
						return popup.toast("提现金额不能超过慧币余额");

					}

					if(!self.checkEmpty(self.weixin)) {
						return popup.toast("请输入收款微信号");
					}

					$.post('/app/wxmp/user/getcash', {
						amount: self.amount,
						alipay: self.alipay,
						weixin: self.weixin
					}, function(res) {

						if(res.errno == 0) {
							self.balance = self.balance - self.amount;
							popup.prompt(res.data);

						} else {
							popup.prompt(res.errmsg);
						}
					});

				},
				tapcash(amt) {
					this.amount = amt;

				},
				checkEmpty(str) {
					str = str.replace(/(^\s*)|(\s*$)/g, "");
					return(str.length) == 0 ? false : true;
				},
				checkAmount(value) {
					var pattern = /(^([1-9]\d{0,15}|0)([.]?|(\.\d{1,2})?)$)/;
					return pattern.test(value);

				}
			}

		});
	</script>

</html>